package com.ly.mpayment.persist.service.zero;

import com.ly.mpayment.persist.entity.ZeroBalance;
import com.ly.mpayment.persist.entity.ZeroBalanceUp;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Map;

@Service
public class ZeroBalanceServiceUpImpl extends AbstractService<ZeroBalanceUp, Serializable> implements ZeroBalanceUpService {

    @Override
    public Page<ZeroBalanceUp> pageZero(Map<String, Object> parameters, int start, int pageSize) {
        String hql = " select z from ZeroBalanceUp z left join fetch z.user u where 1 = 1 " +
                "  #[and u.useruuid = :userId ]#  ";

        if(parameters.containsKey(":createtime")){
            hql += " and z.createTime >= '"+parameters.get(":createtime").toString()+"'";
            parameters.remove(":createtime");
        }
        if(parameters.containsKey(":endtime")){
            hql += " and z.createTime <= '"+parameters.get(":endtime").toString()+"'";
            parameters.remove(":endtime");
        }
        hql += "  order by z.createTime desc ";
        return this.findPageByNamed(hql, parameters, start, pageSize);
    }

    @Override
    public boolean saveZeroBalance(ZeroBalanceUp zeroBalance) {
        if(zeroBalance != null){
            this.saveOrUpdate(zeroBalance);
            return true;
        }
        return false;
    }

}
